package com.itheima.goods.mapper;

import com.github.pagehelper.Page;

import com.itheima.annotation.AutoFill;
import com.itheima.enumeration.OperationType;
import com.itheima.goods.dto.DishPageQueryDTO;
import com.itheima.goods.pojo.Dish;
import com.itheima.goods.pojo.DishFlavor;
import com.itheima.goods.vo.DishOverViewVO;
import com.itheima.goods.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {


    /**
     * 菜品分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageselect(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 菜品起售、停售
     *
     * @param status
     * @param id
     * @return
     */
    @Update("update dish set status=#{status} where id=#{id}")
    void updateStatus(Integer status, Long id);

    DishVO findById(Long id);

    /**
     * 根据分类id查询菜品
     *
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> listDish(Long categoryId);

    /**
     * 菜品添加
     *
     * @param dish
     */
    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user) " +
            "VALUES(#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    void addDish(Dish dish);

    /**
     * 根据菜品id给添加口味
     *
     * @param flavor
     */
    @Insert("insert into dish_flavor(dish_id, name, value) VALUES (#{dishId},#{name},#{value})")
    void addByDishById(DishFlavor flavor);

    /**
     * 批量删除根据ids
     *
     * @param ids
     */

    void deleteByIds(Long[] ids);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);


    List<Dish> selectByIds(Long[] ids);

    /**
     * 根据id查询菜品状态
     * @param id
     * @return
     */
    @Select("select status from dish where id=#{id}")
    Long selectStatus(Long id);
    //====================================
    /**
     * 根据分类id查询菜品以及口味
     * @param categoryId
     * @return
     */
    List<DishVO> selectByCategoryId(Long categoryId);

    @Select("select * from dish where id=#{dishId}")
    Dish findByDishId(Long dishId);
    /**
     * 查询菜品总览
     * @return
     */
    DishOverViewVO overviewDishes();
}
